package edu.hitwh.record;

import edu.hitwh.entity.Book;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class BookRecord {
    private Long id;
    private String title;
    private String author;
    private String isbn;
    private Integer availableCopies;
    private Integer totalCopies;
    public static BookRecord fromEntity(Book book) {
        return BookRecord.builder()
                .id(book.getId())
                .title(book.getTitle())
                .author(book.getAuthor())
                .isbn(book.getIsbn())
                .availableCopies(book.getAvailableCopies())
                .totalCopies(book.getTotalCopies())
                .build();
    }

    public Book toEntity() {
        return Book.builder()
               .id(id)
               .title(title)
               .author(author)
               .isbn(isbn)
               .availableCopies(availableCopies)
               .totalCopies(totalCopies)
               .build();
    }
}
